//买卖股票的最佳时机含冷冻期
//https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-cooldown/description/

class Solution {
public:
    int maxProfit(vector<int>& prices) 
    {
        int n = prices.size();
        vector<int> f(n);
        auto g = f,z = f;

        g[0] = -prices[0];
        
        for(int i = 1; i < n; i++)
        {
            f[i] = g[i - 1] + prices[i];
            g[i] = max(g[i - 1],z[i-1] - prices[i]);
            z[i] = max(z[i - 1],f[i - 1]);
        }
        return max(max(f.back(),g.back()),z.back());
    }
};